<template>
  <div>
    <div>
      <el-form :inline="true" size="medium">
        <!-- <el-form-item label="出发地：">
          <el-input placeholder="全部" v-model="queryObj.start_address">
          </el-input>
        </el-form-item> -->
        <el-form-item clearable label="系列：">
          <el-select v-model="queryObj.series_id" placeholder="全部">
            <el-option
              v-for="item in seriesList"
              :key="item.series_id"
              :label="item.series_name"
              :value="item.series_id"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item clearable label="状态：">
          <el-select v-model="queryObj.audit_status" placeholder="全部">
            <el-option
              v-for="(item, key) in statusList"
              :key="key"
              :label="item"
              :value="key"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-input
            placeholder="请输入优惠券名称"
            v-model="queryObj.query_value"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getMainListReset"
            ><i class="iconfont icon-search"></i>查询</el-button
          >
          <el-button type="primary" size="medium" @click="goto('')"
          ><i class="iconfont icon-plus"></i>添加</el-button
          >
          <el-button type="danger" size="medium" @click="goto('')"
            ><i class="iconfont icon-delete"></i>删除</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div class="mytable">
      <el-table
        :data="mainList"
        tooltip-effect="dark"
        stripe
        style="width: 100%"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="标签分类">
          <template slot-scope="scope">
            {{ scope.row.series_name }}
          </template>
        </el-table-column>
        <el-table-column label="优惠券名称">
          <template slot-scope="scope">
            {{ scope.row.coupon_name }}
          </template>
        </el-table-column>
        <el-table-column label="余量">
          <template slot-scope="scope">
            {{ scope.row.sum_count - scope.row.receive_count }}
          </template>
        </el-table-column>
        <el-table-column label="总量">
          <template slot-scope="scope">
            {{ scope.row.sum_count }}
          </template>
        </el-table-column>
        <el-table-column label="已使用">
          <template slot-scope="scope">
            {{ scope.row.use_count }}
          </template>
        </el-table-column>
        <el-table-column label="加入领券中心">
          <template slot-scope="scope">
            {{ scope.row.is_core ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column label="单笔满">
          <template slot-scope="scope">
            {{ scope.row.full_money }}
          </template>
        </el-table-column>
        <el-table-column label="立减">
          <template slot-scope="scope">
            {{ scope.row.reduction_money }}
          </template>
        </el-table-column>
        <el-table-column label="有效期" width="200">
          <template slot-scope="scope">
            {{scope.row.start_time | formatDate('yyyy-MM-dd')}}
            <span>至</span>
            {{scope.row.end_time | formatDate('yyyy-MM-dd')}}
          </template>
        </el-table-column>
        <el-table-column label="派发用户">
          <template slot-scope="scope">
            {{ scope.row.member_name }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <!-- <el-button type="text" @click="golook(scope.row)"
              ><i class="iconfont icon-liulan"></i>查看</el-button
            > -->
            <el-button type="text" @click="goto(scope.row)"
              ><i class="iconfont icon-edit"></i>编辑</el-button
            >
            <el-button type="text" @click="del(scope.row)"
              ><i class="iconfont icon-del"></i>删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        class="pagecon"
        background
        layout="total, sizes, prev, pager, next"
        @current-change="_mainList"
        @size-change="_mainList"
        :page-size.sync="page.limit"
        :page-sizes="pageSizeArr"
        :current-page.sync="page.page"
        :total="page.total"
      >
      </el-pagination>
    </div>

    <!-- // 审核详情对话框 -->
    <!-- <el-dialog title="审核详情" :visible.sync="dialogTableVisible" width="700">
      <el-table :data="auditList">
        <el-table-column label="审核时间" width="100">
          <template slot-scope="scope">
            <p>{{ scope.row.init_time | formatDate('yyyy-MM-dd') }}</p>
          </template>
        </el-table-column>
        <el-table-column prop="user_name" label="审核人员"></el-table-column>
        <el-table-column  label="审核结果">
          <template slot-scope="scope">
            <p>{{ statusList[scope.row.audit_status] }}</p>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="反馈详情"></el-table-column>
      </el-table>
      <div slot="footer">
        <el-button type="primary" @click="dialogTableVisible = false">关 闭</el-button>
      </div>
    </el-dialog> -->

  </div>
</template>

<script>
import discountCouponAPI from 'api/marketingManagement/discountCouponAPI';
import { pageSizeArr } from "common/config/constConfig";
import { getSeriesAll } from "api/lineManagement/seriesMgAPI";
import config from "api/config";
import {mapMutations} from 'vuex'

export default {
  components: {},
  computed: {},
  data() {
    return {
      // statusList: line_audit_status,
      // lineStatus: line_status,
      // auditList: [],
      imgUrl: config.imgUrl,
      dialogTableVisible: false,
      pageSizeArr,
      queryObj: {},
      mainList: [],
      seriesList: [],
      page: {
        total: 0,
        page: 1,
        limit: 10
      }
    };
  },
  methods: {
    ...mapMutations('middleData', ['setDiscountCouponObj']),

    goto(row) {
      let data = {path: '/home/discountCouponDetail'}
      // if(row) {
      //   data.query = {
      //     id: row.coupon_id,
      //     ...row
      //   }
      // }
      this.setDiscountCouponObj({...row})
      this.$router.push(data)
    },


    del(row) {
      this.$confirm("是否确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this._del(row);
      });
    },
    _del(row) {
      discountCouponAPI('del', {coupon_id: row.coupon_id}).then(res => {
        this._caozuoAfter(res.rMsg);
      });
    },
    // filter fun
    _caozuoAfter(msg) {
      this.dialogFormVisible = false;
      this.$message({
        message: msg,
        type: "success"
      });
      this._mainList();
    },
    getMainListReset() {
      this.page.page = 1;
      this._mainList();
    },
    // 获取
    _mainList() {
      let data = { ...this.queryObj };
      data.pageInfo = { ...this.page };
      discountCouponAPI('get', data).then(res => {
        // let pageInfo = res.pageInfo;
        // this.page.total = pageInfo.Total;
        // this.page.page = pageInfo.page;
        res.rData.forEach(item => {
          item.reduction_money /= 100
          item.full_money /= 100
        })
        this.mainList = res.rData
      });
    },
    // huo qu 系列
    async _getSeriesAll() {
      let res = await getSeriesAll();
      this.seriesList = res.rData;
    }
  },
  created() {
    this._mainList();
    this._getSeriesAll();
  }
};
</script>

<style lang="scss" scoped></style>
